import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.weight'] = 'bold'
plt.rcParams['mathtext.fontset'] = 'stix'

def draw_heat_map():
    xLabel = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
    yLabel = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']

    # xLabel = ['1', '2', '3', '4', '5', '6', '7', '8']
    # yLabel = ['1', '2', '3', '4', '5', '6', '7', '8']

    # xLabel = ['1', '2', '3', '4']
    # yLabel = ['1', '2', '3', '4']

    # data = np.array([
    #     [0.5, 0.5, 0.5, 0.5],
    #     [0.5, 0.5, 0.5, 0.5],
    #     [0.5, 0.5, 0.5, 0.5],
    #     [0.5, 0.5, 0.5, 0.5]
    # ])
    
    data = np.array([
        [0.7, 1.3, 0.8, 2.0, 1.8, 1.2, 1.6, 1.3, 2.2, 2.1, 2.7, 2.9],
        [2.1, 1.7, 1.8, 3.8, 4.1, 3.9, 1.9, 1.6, 1.6, 2.1, 2.0, 2.1],
        [1.0, 1.3, 1.4, 2.1, 2.8, 3.1, 2.5, 2.0, 2.7, 4.2, 3.8, 3.6],
        [1.0, 1.7, 1.7, 2.6, 2.8, 2.4, 2.1, 1.5, 1.8, 2.4, 2.8, 2.9],
        [2.6, 2.2, 1.7, 3.3, 3.5, 4.1, 1.9, 1.9, 2.3, 2.4, 2.3, 2.2],
        [1.4, 2.1, 2.2, 2.7, 3.4, 3.3, 2.8, 2.1, 2.3, 4.0, 3.9, 3.3],
        [1.5, 1.9, 2.0, 4.3, 3.9, 3.2, 3.2, 3.1, 3.1, 2.9, 3.4, 3.8],
        [3.1, 2.2, 1.9, 2.8, 3.9, 4.1, 1.6, 1.1, 1.3, 3.1, 2.7, 2.6],
        [2.1, 2.3, 3.0, 4.1, 4.2, 3.8, 3.4, 2.8, 3.0, 3.7, 4.1, 4.4],
        [1.3, 1.6, 1.2, 3.5, 3.2, 3.1, 2.4, 2.7, 3.0, 4.0, 3.7, 3.8],
        [3.4, 3.1, 3.3, 4.4, 4.4, 3.4, 1.4, 1.2, 1.4, 3.2, 3.0, 2.8],
        [1.3, 2.0, 2.5, 3.8, 4.5, 5.0, 3.8, 4.0, 3.4, 4.5, 4.3, 4.4],
    ])

    fig,  ax = plt.subplots()
    ax.set_yticks(range(len(yLabel)))
    ax.set_yticklabels(yLabel, fontdict={'size': 12})
    ax.set_xticks(range(len(xLabel)))
    ax.set_xticklabels(xLabel, fontdict={'size': 12})

    im = ax.imshow(data, cmap='YlGn')

    # plt.colorbar(im)

    for i in range(len(yLabel)):
        for j in range(len(xLabel)):
            ax.text(j, i, np.round(data[i, j], 2), ha='center', va='center', color='black', fontdict={'size': 12})

    # plt.title('aa')
    plt.xlabel('Grid index', fontdict={'size': 16})
    # plt.ylabel('Grid index', rotation=90, fontdict={'size': 16})
    plt.tight_layout()
    plt.show()


def source():
    # BraTs ppt 中全图像香农熵以及掩码概率
    data = np.array([
        [5.12, 10.61, 10.19, 8.28],
        [12.72, 14.57, 14.05, 14.74],
        [13.23, 15.0, 15.0, 14.99],
        [5.77, 14.95, 14.99, 12.13],
    ])

    data = np.array([
        [0.43, 0.53, 0.52, 0.5],
        [0.58, 0.65, 0.62, 0.66],
        [0.59, 0.73, 0.75, 0.73],
        [0.45, 0.69, 0.72, 0.57],
    ])

    data = np.array([
        [0.0, 0.03, 0.07, 0.0, 0.0, 0.0, 0.0, 0.0],
        [0.33, 6.04, 7.02, 0.15, 0.0, 1.54, 5.45, 0.7],
        [3.07, 11.63, 11.45, 4.11, 0.46, 8.71, 11.97, 9.55],
        [5.24, 9.16, 9.14, 10.87, 11.4, 11.21, 11.48, 11.32],
        [4.49, 10.58, 11.78, 12.0, 12.0, 11.99, 11.61, 11.06],
        [4.04, 11.88, 12.0, 12.0, 12.0, 12.0, 12.0, 11.86],
        [0.86, 8.68, 12.0, 12.0, 12.0, 12.0, 12.0, 8.13],
        [0.0, 2.51, 11.37, 11.94, 11.68, 11.99, 10.06, 0.94],
    ])

    # Brats 论文制图数据
    data = np.array([
        [2.2, 0.0, 0.0, 1.0],
        [10.7, 2.9, 4.2, 11.2],
        [9.5, 12.7, 12.6, 10.6],
        [13.7, 13.7, 13.7, 13.7]
    ])

    data = np.array([
        [0.4, 1.3, 0.7, 1.5, 1.0, 1.6, 0.9, 2.0],
        [1.9, 2.0, 2.1, 2.1, 2.4, 2.3, 2.6, 2.8],
        [3.6, 2.2, 3.9, 2.4, 4.2, 2.6, 4.7, 2.9],
        [4.3, 3.2, 4.8, 3.5, 5.2, 4.0, 5.7, 4.5],
        [3.8, 3.8, 4.1, 4.1, 4.5, 4.3, 4.8, 4.7],
        [4.5, 4.6, 4.6, 4.8, 5.0, 5.2, 5.5, 5.6],
        [2.0, 2.7, 2.3, 2.9, 2.6, 3.2, 2.9, 3.7],
        [2.1, 3.1, 2.6, 3.6, 2.8, 3.8, 3.2, 4.1]
    ])

    data = np.array([
        [0.7, 1.3, 0.8, 2.0, 1.8, 1.2, 1.6, 1.3, 2.2, 2.1, 2.7, 2.9],
        [2.1, 1.7, 1.8, 3.8, 4.1, 3.9, 1.9, 1.6, 1.6, 2.1, 2.0, 2.1],
        [1.0, 1.3, 1.4, 2.1, 2.8, 3.1, 2.5, 2.0, 2.7, 4.2, 3.8, 3.6],
        [1.0, 1.7, 1.7, 2.6, 2.8, 2.4, 2.1, 1.5, 1.8, 2.4, 2.8, 2.9],
        [2.6, 2.2, 1.7, 3.3, 3.5, 4.1, 1.9, 1.9, 2.3, 2.4, 2.3, 2.2],
        [1.4, 2.1, 2.2, 2.7, 3.4, 3.3, 2.8, 2.1, 2.3, 4.0, 3.9, 3.3],
        [1.5, 1.9, 2.0, 4.3, 3.9, 3.2, 3.2, 3.1, 3.1, 2.9, 3.4, 3.8],
        [3.1, 2.2, 1.9, 2.8, 3.9, 4.1, 1.6, 1.1, 1.3, 3.1, 2.7, 2.6],
        [2.1, 2.3, 3.0, 4.1, 4.2, 3.8, 3.4, 2.8, 3.0, 3.7, 4.1, 4.4],
        [1.3, 1.6, 1.2, 3.5, 3.2, 3.1, 2.4, 2.7, 3.0, 4.0, 3.7, 3.8],
        [3.4, 3.1, 3.3, 4.4, 4.4, 3.4, 1.4, 1.2, 1.4, 3.2, 3.0, 2.8],
        [1.3, 2.0, 2.5, 3.8, 4.5, 5.0, 3.8, 4.0, 3.4, 4.5, 4.3, 4.4],
    ])

    data = np.array([
        [0.27, 0.25, 0.26, 0.27],
        [0.39, 0.28, 0.29, 0.42],
        [0.35, 0.51, 0.50, 0.38],
        [0.55, 0.71, 0.65, 0.54]
    ])
    
    
if __name__ == '__main__':
    draw_heat_map()